package Splash;

import recursos.miPanel;
import java.awt.BorderLayout;
import java.awt.Color;
import programa.GUi.Acceso;

/**
 *
 * Esta clase en java es la clase que contiene el Main para el sistema
 * desde esta clase el sistema inicia su ejecucion.
 * @author oscar hernandez hernandez
 * @version 0.1
 * Fecha: Domingo 25 de noviembre de 2012
 */

public final class Principal extends javax.swing.JFrame {
    HiloProgreso hilo;
    public Principal() {
        //quita la barra de titulo del sistema
        setUndecorated(true);
        initComponents();
        iniciarSplash();
        //Creamos un objeto HiloProgreso al cual
        //le pasamos por parametro la barra de progreso
        hilo = new HiloProgreso(jProgressBar2);
        //Iniciamos el Hilo
        hilo.start();
        //Le damos tama帽o y posici贸n a nuestro Frame
        this.setLocation(400, 250);
        //Liberamos recursos
        hilo = null;
    }

    public void iniciarSplash() {
        this.getjProgressBar1().setBorderPainted(true);
        this.getjProgressBar1().setForeground(new Color(50, 50, 153, 100));
        this.getjProgressBar1().setStringPainted(true);
    }

    public javax.swing.JProgressBar getjProgressBar1() {
        return jProgressBar2;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jProgressBar2 = new javax.swing.JProgressBar();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jProgressBar2.setBackground(new java.awt.Color(102, 255, 255));
        jProgressBar2.setForeground(new java.awt.Color(50, 189, 189));
        jProgressBar2.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jProgressBar2StateChanged(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jProgressBar2, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(226, Short.MAX_VALUE)
                .addComponent(jProgressBar2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jProgressBar2StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jProgressBar2StateChanged
        if (jProgressBar2.getValue() == 100) {
            this.dispose();
            //Aqui llamamos al JFrame que queremos que aparezca
            Acceso ventana = new Acceso();
            ventana.setVisible(true);
        }
    }//GEN-LAST:event_jProgressBar2StateChanged

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
         miPanel p = new miPanel();
        this.add( p , BorderLayout.CENTER);
        p.repaint();
    }//GEN-LAST:event_formWindowOpened

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {

        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new Principal().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JProgressBar jProgressBar2;
    // End of variables declaration//GEN-END:variables
}
